import { observable, action, makeAutoObservable } from 'mobx';
import request from '@utils/request';
import Cookies from 'js-cookie';
import { apis } from '@http/index';
import List from '../base.list';
import { getFilterString } from '@utils/index';
interface FetchParamsType {
  page?: number;
  limit?: number;
  keyword?: string;
  more?: boolean;
  [index: string]: any;
}
class News {
  list: List;

  constructor() {
    this.list = new List();
    makeAutoObservable(this);
  }

  getListUrl = () => '/url';

  async fetchList({
    page = this.list.page,
    limit = this.list.limit,
    keyword = this.list.keyword,
    more = this.list.more,
    ...rest
  }: FetchParamsType = {}) {
    this.list.isLoading = true;

    let params: any = {};
    // 搜索条件
    if (keyword) {
      params.conditions = getFilterString({ name: keyword });
    }
    // 第几页页和页数
    if (limit !== Infinity) {
      params.paging = `limit=${limit || 10},page=${page || 1}`;
    }
    // 其他参数
    if (rest) {
      params = { ...rest, ...params };
    }
    // const result: Result = await request.get(getListUrl, params);
    const result = {
      data: [
        {
          id: 0,
          time: '2020/7/14',
          status: 'top',
          title: '陕西省超算中心筹建组来国家超算济南中心调研参观',
        },
        {
          id: 3,
          time: '2020/7/14',
          status: 'top',
          title: '陕西省超算中心筹建组来国家超算济南中心调研参观',
        },
      ],
      total: 23,
    };
    setTimeout(() => {
      this.list.update({
        data: more ? [...this.list.data, ...result.data] : result.data,
        total: result.total,
        limit: Number(limit),
        page: Number(page),
        keyword: keyword,
        isLoading: false,
        more: more,
        filters: rest,
      });
    }, 3000);
  }
}

export default News;
